package chapter2;

class Account {
    String accNo;//账户号
    String accName;//账户名
    double balance;//余额

    //无参构造
    public Account() {
        this.accNo = "000";
        this.accName = "未知";
        this.balance = 0;
    }

    //两个参数
    public Account(String accNo, String accName) {
        this.accNo = accNo;
        this.accName = accName;
        this.balance = 0;
    }

    //三个参数
    public Account(String accNo, String accName, double balance) {
        this.accNo = accNo;
        this.accName = accName;
        this.balance = balance;
    }

    //存钱方法
    public void deposit(double money){
        this.balance+=money;
        System.out.println(accName+"成功存入"+money+"元");
    }
    //取钱方法
    public void withdraw(double money){
        //TODO任务
        if(this.balance-money<0&&money>=0){
            System.out.println(accName+"余额不足，无法取出"+money+"元");
        }else {
            this.balance -= money;
            System.out.println(accName+"成功取出"+money+"元");
        }
    }
    //输出方法
    public void printlnfo() {
        System.out.println("账户号："+accNo + " 账户名：" + accName + " 余额：" + balance);
    }
}

public class Text {
    public static void main(String[] args) {
        Account a1 = new Account();
        a1.printlnfo();
        a1.deposit(123);
        a1.printlnfo();
        System.out.println("\n");
        Account a2 = new Account("123", "张三");
        a2.printlnfo();
        a2.withdraw(100);
        a2.printlnfo();
        System.out.println("\n");
        Account a3 = new Account("789", "李四", 1000);
        a3.printlnfo();
        a3.withdraw(100);
        a3.printlnfo();

    }
}
